package com.itbooking.core;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MybatisMetaObjectHandler implements MetaObjectHandler {


    @Override
    public void insertFill(MetaObject metaObject) {
       // 因为我数据库是自动填充的可以忽略不设置
        /* boolean createTime = metaObject.hasSetter("createTime");
        if (createTime) {
            System.out.println("insert =============");
            // cretaeTime 是实体的属性名
            setFieldValByName("createTime", new Date(), metaObject);
        }*/
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        Object updateTime = getFieldValByName("updateTime", metaObject);
        if (updateTime == null) {
            System.out.println("update =============");
            // updateTime 是实体的属性名
            setFieldValByName("updateTime", new Date(), metaObject);
        }
    }
}
